package com.zyz.O_网络编程.TCP.聊天室;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author: vick
 * @Date: 2025/4/17
 * @Description:
 * @version: 1.0
 */
public class Receive extends Thread {
    private Socket socket;

    public Receive(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            //获取输入流，读取消息
            InputStream inputStream = socket.getInputStream();
            Scanner scanner = new Scanner(inputStream);

            while (scanner.hasNextLine()) {
                String str = scanner.nextLine();
                System.out.println(str);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
